import {  ref, reactive } from 'vue'
import { findDictBrand,findDictTypeList} from '@/api/common'
import { dictType,usableStatus} from '@/utils/dict'
import { dataToSelect} from '@/utils'
let router:any = null


/**
 *  获取路由对象
 */
export function getRouterInstance(r) {
  router = r
}

let DT:any = null


// 挂载类型
const mountType = ref<dictType[]>([]) 
// 品牌
const mountBrand = ref<dictType[]>([]) 
// 型号 
const seriesType = ref<dictType[]>([]) 

// 获取data对象
export function getDataInstance(data) {
  DT = data
}

interface optionsType{
  label:string
  value:string | number | null | undefined
}
interface formItemType {
  type: string,
  key: string,
  label: string,
  row: object,
  props: object
  options?: optionsType[]
}

interface OnionsType {
  modalForm:any
  formItem: formItemType[]
  modalRules?:object
}

// 基础信息
export const baseOpions = reactive({
  modalForm: {
    code: null, // 挂载编号
    type:null, // 挂载类型
    brand:null, // 挂载品牌 drone_DJ 大疆  drone_TH 拓恒
    series:null, // 挂载系列 
    status:null, // 可用状态  0 停用 1 可用  2报废
    factoryCode:null, // 原厂编号
  },
  formItem: [
    {
      type: 'input',
      key: 'code',
      label: '挂载编码',
      row: { sm: 8, md: 8  },
      props: { maxlength: '50', clearable: true, placeholder: '请输入挂载编码' }
    },
    {
      type: 'select',
      key: 'type',
      label: '挂载类型',
      options: mountType,
      row: { sm: 8, md: 8 },
      props: { clearable: true, placeholder: '请选择' }
    },
    {
      type: 'select',
      key: 'brand',
      label: '品牌',
      options:mountBrand,
      row: { sm: 8, md: 8 },
      props: { clearable: true, placeholder: '请选择' }
    },
    {
      type: 'select',
      key: 'series',
      label: '挂载型号',
      options: seriesType,
      row: { sm: 8, md: 8 },
      props: { clearable: true, placeholder: '请选择' }
    },
    {
      type: 'select',
      key: 'status',
      label: '可用状态',
      options: usableStatus,
      row: { sm: 8, md: 8 },
      props: { clearable: true, placeholder: '请选择' }
    },
    {
      type: 'input',
      key: 'factoryCode',
      label: '原厂编号',
      row: { sm: 8, md: 8 },
      props: { clearable: true, placeholder: '请选择' }
    },
  ],
  modalRules: {
    type: [{ required: true, message: '请选择挂载类型', trigger: ['change'] }],
    brand: [{ required: true, message: '请选择品牌', trigger: ['change'] }],
    series: [{ required: true, message: '请选择挂载型号', trigger: ['change'] }],
    status: [{ required: true, message: '请选择可用状态', trigger: ['change'] }],
  },
})

// 云台参数
export const otherOpions= reactive({
  modalForm: {
    pitchRange_start:null,
    pitchRange_end:null,
    translationRange_start:null,
    translationRange_end:null,
    rollRange_start:null,
    rollRange_end:null,
    pullUrl:null,
    pushUrl:null,
  },
  modalRules: {
    pullUrl: [{ required: true, message: '请输入拉流地址', trigger: ['change'] }],
    pushUrl: [{ required: true, message: '请输入推流地址', trigger: ['change'] }],
  },
  formItem:  [
    {
      type: 'double_input',
      keys:['pitchRange_start','pitchRange_end'],
      label: '俯仰范围：',
      row: { sm: 8, md: 8 },
      props: { clearable: true, placeholder: '请输入' }
    },
    {
      type: 'double_input',
      keys:['translationRange_start','translationRange_end'],
      label: '平移范围：',
      row: { sm: 8, md: 8 },
      props: { clearable: true, placeholder: '请输入' }
    },
    {
      type: 'double_input',
      keys:['rollRange_start','rollRange_end'],
      label: '横滚范围：',
      row: { sm: 8, md: 8 },
      props: { clearable: true, placeholder: '请输入' }
    },
    {
      type: 'input',
      key: 'pullUrl',
      label: '拉流地址：',
      row: { sm: 8, md: 8 },
      props: { clearable: true, placeholder: '请输入' }
    },
    {
      type: 'input',
      key: 'pushUrl',
      label: '推流地址：',
      row: { sm: 8, md: 8 },
      props: { clearable: true, placeholder: '请输入' }
    },
  ]
})

// 操作记录
export const setpOpions = reactive([
  {
    title:'新增设备',
    description:"七尾 2023.10.10 10:10:00",
    icon:'iconfont icon-chuangjian'
  },
  {
    title:'设备关联：xx无人机',
    description:"七尾领导 2023.10.10 10:10:00",
    icon:'iconfont icon-feiji_qifei'
  },
  {
    title:'解绑设备：xx无人机',
    description:"八尾 2023.10.10 10:10:00",
    icon:'iconfont icon-riqifanwei'
  },
  {
    title:'更改设备状态：报废',
    description:"八尾 2023.10.10 10:10:00",
    icon:'iconfont icon-biaoqian1'
  }
])


//  挂载类型
export const getType = async function () {
  const {code,data=[],msg} = await  findDictTypeList({prefix:'mount'}) as any
  const mount_type = data.find(item=> item.dictType==='mount_type').dateList ||[]
  const mount_brand = data.find(item=> item.dictType==='mount_brand').dateList ||[]
    mountType.value = dataToSelect(mount_type, { label: 'dictLabel', value: 'dictValue' }) 
    mountBrand.value  = dataToSelect(mount_brand, { label: 'dictLabel', value: 'dictValue' }) 
}

//  挂载型号
export const getSeriesType = async function (prefix) {
   const {code,data=[],msg} = await  findDictBrand({prefix}) as any
   seriesType.value=  dataToSelect(data, { label: 'dictLabel', value: 'dictLabel' })
}
